CREATE PROCEDURE coreSchedulerGetAllDue
AS

/*
Get all tasks where
	The next execution date is earlier than now - IE it's due
AND It isn't marked as a finished task
AND It has remaining tickets left, or a remaining ticket count of -1 (infinate)
AND It's either a non expiring task, or it's an expiring task with the expiry date in the future
*/

	SELECT * FROM ScheduledTasks 
	WHERE
		ExecuteNext < GetDate() 	
	AND Finished = 0
	AND	TimesRemaining <> 0
	AND (
		   ((TaskExpires=1) AND (ExpireTask > GetDate()))
		OR (TaskExpires=0)
		)
		
	    
	